package Jw20241002;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description: 两个链表的合并
 * User: 王圆豪
 * Date: 2024-10-02
 * Time: 21:16
 */
public class Test2 {
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<Integer> list1 = new LinkedList<>();
        LinkedList<Integer> list2 = new LinkedList<>();
        int num;
        while (true) {
            if (sc.hasNextInt()) {
                num = sc.nextInt();
                if (num == -1) break;
                list1.add(num);
            } else {
                sc.next();
            }
        }
        while (true) {
            if (sc.hasNextInt()) {
                num = sc.nextInt();
                if (num == -1) break;
                list2.add(num);
            } else {
                sc.next();
            }
        }
        LinkedList<Integer> list = new LinkedList<>();
        int a = 0;
        int b = 0;
        while(a < list1.size() && b < list2.size()){
            if(list1.get(a) < list2.get(b)) {
                list.add(list1.get(a));
                a++;
            }else {
                list.add(list2.get(b));
                b++;
            }
        }
        if (a < list1.size()){
            for (int i = a; i < list1.size(); i++) {
                list.add(list1.get(i));
            }
        }
        if (b < list2.size()){
            for (int i = b; i < list2.size(); i++) {
                list.add(list2.get(i));
            }
        }
        if (list.isEmpty()){
            System.out.println("NULL");
        }else {
            System.out.print(list.get(0));
            for (int i = 1; i < list.size(); i++) {
                System.out.print(" " + list.get(i));
            }
        }
    }
}
